/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.manager.search;

import br.com.foxline.model.NatureWriting;
import br.com.foxline.service.NatureWritingService;
import br.com.foxline.util.ActionTab;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author ely
 */
@ManagedBean
@ViewScoped
public class ManagerSearchNature {

    @EJB
    NatureWritingService natureWritingService;
  
    private NatureWriting natureWriting;
    private List<NatureWriting> natureWritings;
    private NatureWriting editNatureWriting;
    private ActionTab position;
    private boolean visibleTab;
   
    public ManagerSearchNature() {
    }

    @PostConstruct
    public void init() {
        natureWriting = new NatureWriting();
        natureWritings = new ArrayList<NatureWriting>();
        editNatureWriting = new NatureWriting();
        visibleTab = true;
        position = new ActionTab();
    }

    public void reinit() {
        natureWriting = new NatureWriting();
        natureWritings = new ArrayList<NatureWriting>();
    }

    public void searchNature() {
        natureWritings = natureWritingService.findNature(natureWriting);
    }
    
    public void update(){
        
        natureWritingService.find(editNatureWriting.getActCep().getId());
        natureWritingService.updateNatureWriting(editNatureWriting);
        
    }

    public void cancelSearch() {
        position.setIndexTab(0);
        reinit();
    }
    
      
     public void cancelEdit() {
        visibleTab = true;
        position.positionTab(1);
    }
    
      public void resgateNature(NatureWriting nature) {
        this.editNatureWriting = nature;
        visibleTab = false;
        position.positionTab(2);
    }

    public NatureWriting getNatureWriting() {
        return natureWriting;
    }

    public void setNatureWriting(NatureWriting natureWriting) {
        this.natureWriting = natureWriting;
    }

    public List<NatureWriting> getNatureWritings() {
        return natureWritings;
    }

    public void setNatureWritings(List<NatureWriting> natureWritings) {
        this.natureWritings = natureWritings;
    }

    public NatureWriting getEditNatureWriting() {
        return editNatureWriting;
    }

    public void setEditNatureWriting(NatureWriting editNatureWriting) {
        this.editNatureWriting = editNatureWriting;
    }

    public ActionTab getPosition() {
        return position;
    }

    public void setPosition(ActionTab position) {
        this.position = position;
    }

    public boolean isVisibleTab() {
        return visibleTab;
    }

    public void setVisibleTab(boolean visibleTab) {
        this.visibleTab = visibleTab;
    }
}
